<template>
  <div id="app">
    <!-- 头部区域 -->
    <div class="login-header">
      <div><van-icon name="arrow-left" size="30px" @click="$router.go(-1)"  color="white"/></div>
      <div>
        <div class="img-container">
          <img src="/img/avator.jpeg" alt="">
        </div>
      </div>
    </div>
    <!-- 登录主体区域 -->
    <div class="login-body">
      <div class="login-container">
        <div class="userinfo">
          <img src="/img/shouji.png" alt=""><input v-model="u_phone" type="text" placeholder="手机号">
        </div>
        <div class="userinfo">
          <img src="/img/mima.png" alt=""><input @keyup.enter="login" v-model="u_password" type="password" placeholder="密码">
        </div>
        <div class="userinfo remember">
         <van-icon name="checked" size="25px"  :color="isSelect" @click="message" /> <span>记住密码</span>
        </div>
        <div class="userinfo login">
          <button @click="login">登录</button>
        </div>
        <div class="register-tips">
          <span>还没有账号？</span><span class="register"> <router-link to="/register">立即注册</router-link> </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant';
  export default {
    data(){
      return{
       isSelect:'#F15522',
       isRem:false,
       u_phone:'18696603078',
       u_password:'he123456' 
      }
    },
    methods:{
      message(){
        if(this.isSelect=='#999'){
           this.isSelect = '#F15522'
           this.isRem = true
           if(this.u_phone==''||this.u_password=='') return
           localStorage.setItem('uphone',this.u_phone)
           localStorage.setItem('upassword',this.u_password)
        }else{
          this.isSelect = '#999'
          this.isRem = false
          localStorage.removeItem('uphone')
          localStorage.removeItem('upassword')
        }
      },
      login(){
        if(this.u_phone==''|| this.u_password==''){
          Toast.fail('手机号和密码不能为空哦!');
          return
        }
        let formdata = `u_phone=${this.u_phone}&u_password=${this.u_password}`
        this.$axios.post('/users/login',formdata).then(res=>{
          if(res.data.code==200){
            // 把用户返回的数据
            localStorage.setItem('userinfo',JSON.stringify(res.data.result))
            // console.log(res.data.result);
            Toast.success(res.data.msg);
            this.$router.push('/myinfo')
          }else{
            Toast.fail(res.data.msg);
          }
        })
      }
    },
  }
</script>

<style lang="scss" scoped>
@import url('/img/reset.css');
#app{
  input::-webkit-input-placeholder { 
    color:#999;
  }
  background-color: #fff;
  .login-header{
    width: 100vw;
    height: 67vw;
    background: url('/img/loginbac.jpg');
    background-size: cover;
    >div:nth-child(1){
      width: 100vw;
      height: 25%;
      display: flex;
      box-sizing: border-box;
      align-items: center;
      padding-left: .625rem;
    }
    >div:nth-child(2){
      width: 100vw;
      height: 65%;
      display: flex;
      justify-content: center;
      align-items: center;
      .img-container{
        width: 30vw;
        height: 30vw;
        border-radius: 50%;
        position: relative;
        top: -10vw;
        overflow: hidden;
        background-color: white;
        img{
          width: 100%;
        }
      }
    }
  }
  .current{
    color: #F15522;
  }
  .login-body{
    width: 100vw;
    .login-container{
      width: 90vw;
      height: 330px;
      margin: 0 auto;
      padding-top: 3.125rem;
      // background-color: violet;
      .userinfo{
        width: 100%;
        height: 3.4375rem;
        margin-top: 1.25rem;
        border-radius: 1.875rem;
        display: flex;
        align-items: center;
        padding-left: .9375rem;
        box-sizing: border-box;
        border: 1px solid #e7e6e6;
        img{
          width: 1.7rem;
        }
        input{
          width: 70vw;
          height: 95%;
          font-size: .9375rem;
        }
        button{
          width: 100%;
          height: 100%;
          color: white;
          border-radius: 1.875rem;
          background-color: #F15522;
        }
      }
      .login{
        padding-left: 0;
        color: white;
        font-size: .9375rem;
      }
      .register-tips{
        width: 90vw;
        text-align: center;
        line-height: 3.875rem;
        height: 3.875rem;
        span{
          font-size: 1rem;
          color: #999;
        }
        .register{
          color: #F15522;
        }
      }
      .remember{
        border: none;
        margin-top: .625rem;
        span{
          color: #999;
          margin-left: .3125rem;
          font-size: .9375rem;
        }
      }
    }
  }
}
</style>